<h2><?= $this->translate('Listing menu links');?></h2>
<div class="grid_12"><?= $this->flashMessenger(); ?></div>
<div class="clearfix"></div>
<p><a href="<?= $this->url(array(), 'navigation_menuitem_create'); ?>"><?= $this->translate('Create a new menu link');?></a></p>
<?= $this->form;?>
<div class="grid_12 alpha omega">
	<table width="100%">
		<thead>
			<tr>
				<th><?= $this->translate('ID');?></th>
				<th><?= $this->translate('Name');?></th>
				<th><?= $this->translate('Target');?></th>
				<th><?= $this->translate('Uri');?></th>
				<th><?= $this->translate('Ordering');?></th>
				<th><?= $this->translate('Published');?></th>
				<th><?= $this->translate('Parent menu');?></th>
				<th><?= $this->translate('Actions');?></th>
			</tr>
		</thead>
		<tbody>
			<?php if(count($this->menuItems) > 0):?>
				<?php $key = 0;?>
				<?php foreach ($this->menuItems as $value):?>
					<tr class="<?= ($key+1)%2 ? 'tr1' : 'tr2';?>">
						<td style="text-align:center;">
							<?= $value['id'];?>
						</td>
						<td style="text-align:left;">
							<a href="<?= $this->url(array('id' => $value['id']), 'navigation_menuitem_update');?>" title="<?= $this->translate('Edit');?>">
								<?= $value['name'];?>
							</a>
						</td>
						<td style="text-align:center;">
							<?= $value['target'];?>
						</td>
						<td style="text-align:center;width:15%;">
							<a href="<?= $value['uri'];?>">
								<?= $value['uri'];?>
							</a>
						</td>
						<td style="text-align:center;">
							<a href="<?= $this->url(array('id' => $value['id'], 'diff' => '-1'),'navigation_menuitem_ordering');?>">
								&darr;
							</a>&nbsp;
							<a href="<?= $this->url(array('id' => $value['id'], 'diff' => '1'),'navigation_menuitem_ordering');?>">
								&uarr;
							</a>
						</td>
						<td style="text-align:center;">
							<a href="javascript:publish(<?= $value['id'];?>)" id="iconp_<?= $value['id'];?>">
								<?= $this->IconPublished($value['published']);?>
							</a>
						</td>
						<td style="text-align:center;">
							<?= $value['menu'];?>
						</td>
						<td style="text-align:center;">
							<a href="<?= $this->url(array('id' => $value['id']), 'navigation_menuitem_update');?>">
								<?= $this->translate('Edit');?>
							</a>&nbsp;|&nbsp;
							<a href="<?= $this->url(array('id' => $value['id']), 'navigation_menuitem_delete');?>" onclick="return confirm('<?= $this->translate('Are you sure?');?>');">
								<?= $this->translate('Delete');?>
							</a>
						</td>
					</tr>
				<?php $key++;?>
				<?php endforeach;?>
			<?php else: ?>
				<tr>
					<td colspan="7">
						<?= $this->translate('No items menu links');?>
					</td>
				</tr>
			<?php endif; ?>
		</tbody>
	</table>
</div>
<script type="text/javascript">
	function publish(id) {
		var id = id;
		$.post('<?= $this->url(array(),'navigation_menuitem_publish');?>',{"id":id},function(data){
			var obj = $.parseJSON(data);

			for(i in obj) {
				if(obj[i]) {
					$('#iconp_' + i).html('<?= $this->IconPublished(1);?>');
				} else {
					$('#iconp_' + i).html('<?= $this->IconPublished(0);?>');
				}
			}
			
		});
	}
</script>